using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace DataAccess
{
	/// <summary>
	/// Strongly-typed collection for the TblCusFolder class.
	/// </summary>
    [Serializable]
	public partial class TblCusFolderCollection : ActiveList<TblCusFolder, TblCusFolderCollection>
	{	   
		public TblCusFolderCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>TblCusFolderCollection</returns>
		public TblCusFolderCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                TblCusFolder o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the TblCusFolder table.
	/// </summary>
	[Serializable]
	public partial class TblCusFolder : ActiveRecord<TblCusFolder>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public TblCusFolder()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public TblCusFolder(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public TblCusFolder(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public TblCusFolder(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("TblCusFolder", TableType.Table, DataService.GetInstance("DataAccess"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "ID";
				colvarId.DataType = DbType.Int32;
				colvarId.MaxLength = 0;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarCusId = new TableSchema.TableColumn(schema);
				colvarCusId.ColumnName = "CusId";
				colvarCusId.DataType = DbType.Int32;
				colvarCusId.MaxLength = 0;
				colvarCusId.AutoIncrement = false;
				colvarCusId.IsNullable = true;
				colvarCusId.IsPrimaryKey = false;
				colvarCusId.IsForeignKey = true;
				colvarCusId.IsReadOnly = false;
				colvarCusId.DefaultSetting = @"";
				
					colvarCusId.ForeignKeyTableName = "TblCustomers";
				schema.Columns.Add(colvarCusId);
				
				TableSchema.TableColumn colvarType = new TableSchema.TableColumn(schema);
				colvarType.ColumnName = "Type";
				colvarType.DataType = DbType.Int32;
				colvarType.MaxLength = 0;
				colvarType.AutoIncrement = false;
				colvarType.IsNullable = true;
				colvarType.IsPrimaryKey = false;
				colvarType.IsForeignKey = false;
				colvarType.IsReadOnly = false;
				colvarType.DefaultSetting = @"";
				colvarType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarType);
				
				TableSchema.TableColumn colvarFollowCode = new TableSchema.TableColumn(schema);
				colvarFollowCode.ColumnName = "FollowCode";
				colvarFollowCode.DataType = DbType.String;
				colvarFollowCode.MaxLength = -1;
				colvarFollowCode.AutoIncrement = false;
				colvarFollowCode.IsNullable = true;
				colvarFollowCode.IsPrimaryKey = false;
				colvarFollowCode.IsForeignKey = false;
				colvarFollowCode.IsReadOnly = false;
				colvarFollowCode.DefaultSetting = @"";
				colvarFollowCode.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFollowCode);
				
				TableSchema.TableColumn colvarRegDate = new TableSchema.TableColumn(schema);
				colvarRegDate.ColumnName = "RegDate";
				colvarRegDate.DataType = DbType.DateTime;
				colvarRegDate.MaxLength = 0;
				colvarRegDate.AutoIncrement = false;
				colvarRegDate.IsNullable = true;
				colvarRegDate.IsPrimaryKey = false;
				colvarRegDate.IsForeignKey = false;
				colvarRegDate.IsReadOnly = false;
				colvarRegDate.DefaultSetting = @"";
				colvarRegDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRegDate);
				
				TableSchema.TableColumn colvarDoneDate = new TableSchema.TableColumn(schema);
				colvarDoneDate.ColumnName = "DoneDate";
				colvarDoneDate.DataType = DbType.DateTime;
				colvarDoneDate.MaxLength = 0;
				colvarDoneDate.AutoIncrement = false;
				colvarDoneDate.IsNullable = true;
				colvarDoneDate.IsPrimaryKey = false;
				colvarDoneDate.IsForeignKey = false;
				colvarDoneDate.IsReadOnly = false;
				colvarDoneDate.DefaultSetting = @"";
				colvarDoneDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDoneDate);
				
				TableSchema.TableColumn colvarIsDone = new TableSchema.TableColumn(schema);
				colvarIsDone.ColumnName = "IsDone";
				colvarIsDone.DataType = DbType.Boolean;
				colvarIsDone.MaxLength = 0;
				colvarIsDone.AutoIncrement = false;
				colvarIsDone.IsNullable = true;
				colvarIsDone.IsPrimaryKey = false;
				colvarIsDone.IsForeignKey = false;
				colvarIsDone.IsReadOnly = false;
				colvarIsDone.DefaultSetting = @"";
				colvarIsDone.ForeignKeyTableName = "";
				schema.Columns.Add(colvarIsDone);
				
				TableSchema.TableColumn colvarExpertType = new TableSchema.TableColumn(schema);
				colvarExpertType.ColumnName = "ExpertType";
				colvarExpertType.DataType = DbType.String;
				colvarExpertType.MaxLength = -1;
				colvarExpertType.AutoIncrement = false;
				colvarExpertType.IsNullable = true;
				colvarExpertType.IsPrimaryKey = false;
				colvarExpertType.IsForeignKey = false;
				colvarExpertType.IsReadOnly = false;
				colvarExpertType.DefaultSetting = @"";
				colvarExpertType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarExpertType);
				
				TableSchema.TableColumn colvarDescription = new TableSchema.TableColumn(schema);
				colvarDescription.ColumnName = "Description";
				colvarDescription.DataType = DbType.String;
				colvarDescription.MaxLength = -1;
				colvarDescription.AutoIncrement = false;
				colvarDescription.IsNullable = true;
				colvarDescription.IsPrimaryKey = false;
				colvarDescription.IsForeignKey = false;
				colvarDescription.IsReadOnly = false;
				colvarDescription.DefaultSetting = @"";
				colvarDescription.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDescription);
				
				TableSchema.TableColumn colvarExpertId = new TableSchema.TableColumn(schema);
				colvarExpertId.ColumnName = "ExpertId";
				colvarExpertId.DataType = DbType.Int32;
				colvarExpertId.MaxLength = 0;
				colvarExpertId.AutoIncrement = false;
				colvarExpertId.IsNullable = true;
				colvarExpertId.IsPrimaryKey = false;
				colvarExpertId.IsForeignKey = true;
				colvarExpertId.IsReadOnly = false;
				colvarExpertId.DefaultSetting = @"";
				
					colvarExpertId.ForeignKeyTableName = "TblExperts";
				schema.Columns.Add(colvarExpertId);
				
				TableSchema.TableColumn colvarExpDescription = new TableSchema.TableColumn(schema);
				colvarExpDescription.ColumnName = "ExpDescription";
				colvarExpDescription.DataType = DbType.String;
				colvarExpDescription.MaxLength = -1;
				colvarExpDescription.AutoIncrement = false;
				colvarExpDescription.IsNullable = true;
				colvarExpDescription.IsPrimaryKey = false;
				colvarExpDescription.IsForeignKey = false;
				colvarExpDescription.IsReadOnly = false;
				colvarExpDescription.DefaultSetting = @"";
				colvarExpDescription.ForeignKeyTableName = "";
				schema.Columns.Add(colvarExpDescription);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["DataAccess"].AddSchema("TblCusFolder",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public int Id 
		{
			get { return GetColumnValue<int>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("CusId")]
		[Bindable(true)]
		public int? CusId 
		{
			get { return GetColumnValue<int?>(Columns.CusId); }
			set { SetColumnValue(Columns.CusId, value); }
		}
		  
		[XmlAttribute("Type")]
		[Bindable(true)]
		public int? Type 
		{
			get { return GetColumnValue<int?>(Columns.Type); }
			set { SetColumnValue(Columns.Type, value); }
		}
		  
		[XmlAttribute("FollowCode")]
		[Bindable(true)]
		public string FollowCode 
		{
			get { return GetColumnValue<string>(Columns.FollowCode); }
			set { SetColumnValue(Columns.FollowCode, value); }
		}
		  
		[XmlAttribute("RegDate")]
		[Bindable(true)]
		public DateTime? RegDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.RegDate); }
			set { SetColumnValue(Columns.RegDate, value); }
		}
		  
		[XmlAttribute("DoneDate")]
		[Bindable(true)]
		public DateTime? DoneDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.DoneDate); }
			set { SetColumnValue(Columns.DoneDate, value); }
		}
		  
		[XmlAttribute("IsDone")]
		[Bindable(true)]
		public bool? IsDone 
		{
			get { return GetColumnValue<bool?>(Columns.IsDone); }
			set { SetColumnValue(Columns.IsDone, value); }
		}
		  
		[XmlAttribute("ExpertType")]
		[Bindable(true)]
		public string ExpertType 
		{
			get { return GetColumnValue<string>(Columns.ExpertType); }
			set { SetColumnValue(Columns.ExpertType, value); }
		}
		  
		[XmlAttribute("Description")]
		[Bindable(true)]
		public string Description 
		{
			get { return GetColumnValue<string>(Columns.Description); }
			set { SetColumnValue(Columns.Description, value); }
		}
		  
		[XmlAttribute("ExpertId")]
		[Bindable(true)]
		public int? ExpertId 
		{
			get { return GetColumnValue<int?>(Columns.ExpertId); }
			set { SetColumnValue(Columns.ExpertId, value); }
		}
		  
		[XmlAttribute("ExpDescription")]
		[Bindable(true)]
		public string ExpDescription 
		{
			get { return GetColumnValue<string>(Columns.ExpDescription); }
			set { SetColumnValue(Columns.ExpDescription, value); }
		}
		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a TblCustomer ActiveRecord object related to this TblCusFolder
		/// 
		/// </summary>
		public DataAccess.TblCustomer TblCustomer
		{
			get { return DataAccess.TblCustomer.FetchByID(this.CusId); }
			set { SetColumnValue("CusId", value.Id); }
		}
		
		
		/// <summary>
		/// Returns a TblExpert ActiveRecord object related to this TblCusFolder
		/// 
		/// </summary>
		public DataAccess.TblExpert TblExpert
		{
			get { return DataAccess.TblExpert.FetchByID(this.ExpertId); }
			set { SetColumnValue("ExpertId", value.Id); }
		}
		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int? varCusId,int? varType,string varFollowCode,DateTime? varRegDate,DateTime? varDoneDate,bool? varIsDone,string varExpertType,string varDescription,int? varExpertId,string varExpDescription)
		{
			TblCusFolder item = new TblCusFolder();
			
			item.CusId = varCusId;
			
			item.Type = varType;
			
			item.FollowCode = varFollowCode;
			
			item.RegDate = varRegDate;
			
			item.DoneDate = varDoneDate;
			
			item.IsDone = varIsDone;
			
			item.ExpertType = varExpertType;
			
			item.Description = varDescription;
			
			item.ExpertId = varExpertId;
			
			item.ExpDescription = varExpDescription;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varId,int? varCusId,int? varType,string varFollowCode,DateTime? varRegDate,DateTime? varDoneDate,bool? varIsDone,string varExpertType,string varDescription,int? varExpertId,string varExpDescription)
		{
			TblCusFolder item = new TblCusFolder();
			
				item.Id = varId;
			
				item.CusId = varCusId;
			
				item.Type = varType;
			
				item.FollowCode = varFollowCode;
			
				item.RegDate = varRegDate;
			
				item.DoneDate = varDoneDate;
			
				item.IsDone = varIsDone;
			
				item.ExpertType = varExpertType;
			
				item.Description = varDescription;
			
				item.ExpertId = varExpertId;
			
				item.ExpDescription = varExpDescription;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn CusIdColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn TypeColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn FollowCodeColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn RegDateColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn DoneDateColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn IsDoneColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        public static TableSchema.TableColumn ExpertTypeColumn
        {
            get { return Schema.Columns[7]; }
        }
        
        
        
        public static TableSchema.TableColumn DescriptionColumn
        {
            get { return Schema.Columns[8]; }
        }
        
        
        
        public static TableSchema.TableColumn ExpertIdColumn
        {
            get { return Schema.Columns[9]; }
        }
        
        
        
        public static TableSchema.TableColumn ExpDescriptionColumn
        {
            get { return Schema.Columns[10]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"ID";
			 public static string CusId = @"CusId";
			 public static string Type = @"Type";
			 public static string FollowCode = @"FollowCode";
			 public static string RegDate = @"RegDate";
			 public static string DoneDate = @"DoneDate";
			 public static string IsDone = @"IsDone";
			 public static string ExpertType = @"ExpertType";
			 public static string Description = @"Description";
			 public static string ExpertId = @"ExpertId";
			 public static string ExpDescription = @"ExpDescription";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
